package com.ww.springboot.boot.algorithm.string;

/**
 * 回文字符串
 *
 * @author wanwei
 * @since 2021-03-07 11:47
 */
public class HuiWenDemo {

    public static void main(String[] args) {
        String ss = "ababbaababbaba";
        System.out.println("是否回文字符串:" + method(ss));
    }

    /**
     * 判断是否回文字符串
     *
     * @param s
     * @return
     */
    private static Boolean method(String s) {
        if (s.length() < 2) {
            return true;
        }

        int length = s.length();
        int i = 0;
        while (true) {
            if (s.charAt(i) != s.charAt(length - i - 1)) {
                return false;
            }
            i++;

            if (i > length / 2) {
                return true;
            }
        }
    }
}
